import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuBar;
import javax.swing.JRadioButton;



public class ColorNamesInfoVisTester extends JFrame implements ActionListener{
	
	private ColorNamesInfoVis cniv;
	private int filter[] = new int[2];
	public static String bothg = "Both";
	public static String male = "Male";
	public static String female = "Female";
	public static String bothcb = "Both";
	public static String colorblind = "Colorblind";
	public static String noncolorblind = "Non-Colorblind";
	
	public ColorNamesInfoVisTester() {
		setTitle("Color Names Info Vis");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		cniv = new ColorNamesInfoVis();
		filter[0] = 0;
		filter[1] = 2;
		
		getContentPane().add(cniv);
		
		//setup menu bar
		JMenuBar menubar = new JMenuBar();
		JLabel filter = new JLabel(" Gender Filter: ");
		
		JRadioButton bRadio = new JRadioButton(bothg);
		bRadio.setSelected(true);
		bRadio.setActionCommand("bothg");
		JRadioButton mRadio = new JRadioButton(male);
		mRadio.setActionCommand(male);
		JRadioButton fRadio = new JRadioButton(female);
		fRadio.setActionCommand(female);
		
		JLabel color = new JLabel("                             Colorblind Filter: ");
		
		JRadioButton aRadio = new JRadioButton(bothcb);
		aRadio.setActionCommand("bothcb");
		JRadioButton cRadio = new JRadioButton(colorblind);
		cRadio.setActionCommand(colorblind);
		JRadioButton ncRadio = new JRadioButton(noncolorblind);
		ncRadio.setSelected(true);
		ncRadio.setActionCommand(noncolorblind);
		
		//add action listener
		bRadio.addActionListener(this);
		mRadio.addActionListener(this);
		fRadio.addActionListener(this);
		
		aRadio.addActionListener(this);
		cRadio.addActionListener(this);
		ncRadio.addActionListener(this);
		
		ButtonGroup group = new ButtonGroup();
		group.add(mRadio);
		group.add(fRadio);
		group.add(bRadio);
		
		ButtonGroup cGroup = new ButtonGroup();
		cGroup.add(aRadio);
		cGroup.add(cRadio);
		cGroup.add(ncRadio);
		
		menubar.add(filter);
		menubar.add(bRadio);
		menubar.add(mRadio);
		menubar.add(fRadio);
		
		menubar.add(color);
		menubar.add(aRadio);
		menubar.add(cRadio);
		menubar.add(ncRadio);
		
		
		this.setJMenuBar(menubar);
		pack();
		setVisible(true);
	}

	public static void main(String args[]) {
		new ColorNamesInfoVisTester();
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getActionCommand() == "bothg"){
			filter[0] = 0;
		}
		else if(e.getActionCommand() == male){
			filter[0] = 1;
		}
		else if(e.getActionCommand() == female){
			filter[0] = 2;
		}
		
		if(e.getActionCommand() == "bothcb"){
			filter[1] = 0;
		}
		else if(e.getActionCommand() == colorblind){
			filter[1] = 1;
		}
		else if(e.getActionCommand() == noncolorblind){
			filter[1] = 2;
		}
		
		cniv.setFilter(filter);
	}
}